package com.zr.dao;

import com.zr.pojo.Article;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ArticleDao {

    @Insert("insert into ev_articles (id, title, content, cover_img, pub_date, state, is_delete, cate_id, author_id)" +
            "values (null, #{title}, #{content}, #{cover_img}, #{pub_date}, #{state}, #{is_delete}, #{cate_id}, #{author_id})")
    int add(Article article);


    //逻辑删
    @Update("update ev_articles set is_delete = 1 where id = #{id}")
    int delete(int id);

//    @Select("select * from ev_articles where is_delete = 0 order by id")
//    List<Article> selectAll();

    //动态sql实现多条件查询
    List<Article> selectWithConditions(@Param("cate_id") int cate_id, @Param("state") String state);

    @Select("select * from ev_articles where id = #{id} and is_delete = 0")
    Article selectByID(int id);

    @Update("update ev_articles set title = #{title}, cate_id = #{cate_id}, content = #{content}, cover_img = #{cover_img}, state = #{state}" +
            " where id = #{id}")
    int updateById(Article article);


}
